package cn.hchaojie.camp.javafx.animation;

import javafx.animation.ParallelTransition;
import javafx.animation.RotateTransition;
import javafx.animation.Transition;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;

public class DemoParallel extends Application {

	@Override
	public void start(Stage stage) throws Exception {
		Scene scene = new Scene(createContents(), 600, 300);
		
		stage.setScene(scene);
		stage.show();
	}
	
	// 在这里创建页面布局
	private Parent createContents() {
		StackPane stack = new StackPane();
		
		String url = getClass().getResource("mnls.png").toExternalForm();
		ImageView image = new ImageView(url);

		image.setFitHeight(100);
		image.setPreserveRatio(true);
		
		ParallelTransition parallel = new ParallelTransition();
		
		TranslateTransition translate = new TranslateTransition(
				Duration.millis(1000), image);
		translate.setByX(100);
		translate.setByY(100);
		
		RotateTransition rotate = new RotateTransition(
				Duration.millis(500), image);
		rotate.setByAngle(360);
		
		parallel.getChildren().addAll(translate, rotate);
		parallel.setCycleCount(Transition.INDEFINITE);
		parallel.setAutoReverse(true);
		
		parallel.play();
		
		stack.getChildren().add(image);

		return stack;
	}

	public static void main(String[] args) {
		launch(args);
	}
}
